<?php
/* 
 * Copyright (c) 2018-2021   All rights reserved.
 * 
 * 创建时间：2021-09-24 07:10
 *
 * 项目：rm  -  $  - run.php
 *
 * 作者：liwei 
 */

use modules\levpays\modules\baidupay\sdk\baiduPayment;
use modules\levpays\table\tradesHelper;

/* @var $goods array @see modules\levpays\payIdenHelper::getPayGoodsInfo() */
?>
<?=\modules\levpays\modules\baidupay\widgets\payWidget::miniJs(),\lev\base\Assetsv::qrcodeJs(1);?>

<script>
jQuery(function () {

<?php if (Lev::ckmobile() || \modules\levpays\modules\baidupay\baidupayHelper::checkBaiduUserAgent()):?>

    levpaysPay.setPaytypeidInit[2] = function () {
        levpaysPay.pre = 'BDUMINI';

    };

    levpaysPay.setPaytypeidSubmit[2] = function () {
        levpaysPay.pre = 'BDUMINI';

        var orderInfo = '<?=Lev::base64_encode_url(json_encode(baiduPayment::createOrder($goods['tradeNo'], $goods['name'], $goods['paymoney'], $goods['descs'])));?>';

        //swan.webView.navigateTo({url: '/pages/auth/index'});
        swan.webView.navigateTo({url:'/pages/pay/pay?orderInfo='+orderInfo});
        swan.webView.postMessage({orderInfo: orderInfo});

    };
    if (navigator.userAgent.indexOf('baiduboxapp/') > -1) {
        jQuery('.paytypeidbox-0').hide();
        jQuery('.paytypeidbox-1').hide();
    }else {
        jQuery('.paytypeidbox-2').hide();
    }
    //jQuery('.paytypeidbox-1 input[name=paytypeid]').click();

<?php elseif ($qrcodePaylink = \modules\levpays\modules\baidupay\widgets\payWidget::qrcodePaylink($goods['tradeId'])):?>

    levpaysPay.setPaytypeidInit[2] = function () {
        levpaysPay.pre = 'BDUPC';

        jQuery('.levpaysPaySubmitBtn').addClass('disabled').html('请使用百度APP扫码支付');
        setLevpaysBduminiQrcode();
    };

    levpaysPay.setPaytypeidSubmit[2] = function () {
        levpaysPay.pre = 'BDUPC';

        Levme.showNotices('请使用百度APP扫码支付');
        setLevpaysBduminiQrcode();
    }

    setLevpaysBduminiQrcode();
    function setLevpaysBduminiQrcode() {
        jQuery('#levpays-qrcode').html('').removeClass('hiddenx');
        jQuery('.levpays-qrcode-box').removeClass('hiddenx');
        new QRCode('levpays-qrcode', {
            text: '<?=$qrcodePaylink?>',
            width: 148,
            height: 148,
            colorDark: "#000000",
            colorLight: "#ffffff",
            correctLevel: QRCode.CorrectLevel.Q
        });
    }

<?php else:?>
    jQuery('.paytypeidbox-2').hide();
<?php endif;?>

});
</script>